package hlhj.fhp.burst;

import android.annotation.SuppressLint;

import java.text.SimpleDateFormat;

/**
 * Created by Administrator on 2018\5\16 0016.
 */

public class TimeUtils {
    /**
     * 将一个时间戳转换成提示性时间字符串，如刚刚，1秒前
     *
     * @param timeStamp
     * @return
     */
    public static String convertTimeToFormat(long timeStamp) {
        String times = timeStamp + "";
        if (times.length() >= 11) {
            timeStamp = Long.parseLong(times) / (long) 1000;
        }
        long curTime = System.currentTimeMillis() / (long) 1000;

        long time = curTime - timeStamp;

        if (time < 60 && time >= 0) {
            return "刚刚";
        } else if (time >= 60 && time < 3600) {
            return time / 60 + "分钟前";
        } else if (time >= 3600 && time < 3600 * 24) {
            return time / 3600 + "小时前";
        } else if (time >= 3600 * 24 && time < 3600 * 24 * 10) {
            return time / 3600 / 24 + "天前";
        } else {
            return timeStampToStr(timeStamp);
        }
    }
    /**
     * 时间戳转化为时间格式
     *
     * @param timeStamp
     * @return
     */
    public static String timeStampToStr(long timeStamp) {
        String times = String.valueOf(timeStamp);
        if (times.length() >= 11) {
            timeStamp = Long.parseLong(times) / (long) 1000;
        }
        @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = sdf.format(timeStamp * 1000);
        return date;
    }
}
